package com.hngy.xpq.android_practice.rewrite;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class MyRewriteView extends ScrollView {

    OnTouchListener m;
    private float xD , yD , xL , yL;
    public MyRewriteView(Context context) {
        super(context);
    }

    public MyRewriteView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRewriteView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptHoverEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                xD = yD = 0f;
                xL = event.getX();
                yL = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                final float cX = event.getX();
                final float cY = event.getY();
                xD += Math.abs(cX - xL);
                yD += Math.abs(cY - yL);
                xL = cX;
                xL = cY;
                if (xD > yD){
                    return false;
                }
                break;
        }
        return super.onInterceptHoverEvent(event);
    }
}
